<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>后台管理主页面</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/admin_dashboard.css') }}">
    <script>
        function loadPage(url) {
            var xhr = new XMLHttpRequest();
            xhr.open('GET', url, true);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    document.getElementById('content').innerHTML = xhr.responseText;
                }
            };
            xhr.send();
        }

        function submitForm() {
            var form = document.getElementById('editUserForm');
            var formData = new FormData(form);
            var xhr = new XMLHttpRequest();
            xhr.open('POST', form.action, true);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    document.getElementById('content').innerHTML = xhr.responseText;
                }
            };
            xhr.send(formData);
        }

        function submitCommonSenseForm() {
            var form = document.getElementById('commonSenseForm');
            if (!form) {
                console.error('未找到常识表单');
                return;
            }
            var formData = new FormData(form);
            var xhr = new XMLHttpRequest();
            xhr.open('POST', form.action, true);
            xhr.onreadystatechange = function () {
                document.getElementById('content').innerHTML = xhr.responseText;
            };
            xhr.send(formData);
        }

        function confirmClearKnowledge() {
            console.log('confirmClearKnowledge called');
            if (confirm('确定要清空知识库吗？此操作不可恢复！')) {
                loadPage('{{ url_for('clear_knowledge') }}');
            }
        }

        // 页面加载时默认显示欢迎页
        window.onload = function () {
            loadPage('{{ url_for('welcome') }}');
        };
    </script>
</head>
<body>
<!-- 顶部导航栏 -->
<header class="top-nav">
    <nav class="nav-container">
        <ul class="nav-list left-nav">
            <li class="nav-item">
                <span class="navbar-text me-3">欢迎管理员</span>
            </li>
        </ul>
        <ul class="nav-list right-nav">
            <li class="nav-item">
                <a class="nav-link" href="{{ url_for('logout') }}">退出</a>
            </li>
        </ul>
    </nav>
</header>

<!-- 页面主体 -->
<div class="main-container">
    <!-- 左侧导航栏 -->
    <aside class="sidebar">
        <ul class="sidebar-list">
            <li class="sidebar-item">
                <a class="sidebar-link" href="{{ url_for('welcome') }}"
                   onclick="loadPage(this.href); return false;">欢迎页</a>
            </li>
            <li class="sidebar-item">
                <a class="sidebar-link" href="{{ url_for('users') }}"
                   onclick="loadPage(this.href); return false;">注册用户管理</a>
            </li>
            <li class="sidebar-item">
                <a class="sidebar-link" href="{{ url_for('view_knowledge_items') }}"
                   onclick="loadPage(this.href); return false;">知识单条管理</a>
            </li>
            <li class="sidebar-item">
                <a class="sidebar-link" href="{{ url_for('import_export_knowledge') }}"
                   onclick="loadPage(this.href); return false;">Excel知识导入</a>
            </li>
			<li class="sidebar-item">
                <a class="sidebar-link" href="{{ url_for('common_sense_management') }}"
                   onclick="loadPage(this.href); return false;">常识编辑</a>
            </li>
            </ul>
        </aside>

        <!-- 右侧内容区域 -->
        <main id="content" class="content-area">

        </main>
    </div>
    </body>
    </html>
    </html>